﻿$(document).on("change2 change", "#c-ocation_class", function (e) {
    let that = $(this);

    if (e.type == "change2") {
        $.ajax({
            url: "/ocation/ocation/lists2?XDEBUG_SESSION_START=54354",
            data: {
                cityId: Config.admin['city_id'],
                relType: Config.admin['rel_type'],
                relId: Config.admin['rel_id'],
                addresslv_id: $("#c-address_lv").val()
            },
            type: "GET",
            success: function (data, textStatus, jqXHR) {
                httpInfo(jqXHR, this);
                var $ocation = that;
                $ocation.empty();
                var list = JSON.parse(data);
                $.each(list["all"]["list"], function (index, ocation) {
                    disabled = (ocation.address_lv_octionlevel < 3 || typeof (ocation.address_lv_octionlevel) == 'undefined') ? " disabled  class='disabled'" : "";
                    checked = "";
                    if (row && Array.isArray(row.ocation_id)) {

                        checked = row.ocation_id.includes(ocation.id) ? "selected" : "";
                    } else if (row && row.ocation_id == ocation.id) {
                        checked = "selected";
                    }else{
                        checked = "";
                    }
                    weekdays = ocation && ocation.weekdays?" weekdays='"+ocation.weekdays+"'":"";
                    schedule_data = ocation && ocation.schedule_data?" schedule_data='"+ocation.schedule_data+"'":"";
                    already_schedule = ocation && ocation.already_schedule?" already_schedule='"+ocation.already_schedule+"'":"";
                    disable_week_time = ocation && ocation.disable_week_time?" disable_week_time='"+ocation.disable_week_time+"'":"";
                    $ocation.append('<option value="' + ocation.id + '"' +weekdays+schedule_data+already_schedule+disable_week_time+disabled + ' ' + checked + ' ' + ' parent="' + ocation.parent + '" level="' + ocation.level + '">' + ocation.name + '</option>');
                });
                // 设置下拉框高度为400px
                $ocation.css('height', '400px');
                hasweek();
                hasdaytime();
            },
            error: function (xhr, status, error) {
            }
        });
    } else if (e.type == "change") {
        if ($("#c-ocation_pid").length > 0) {
            level = $("#c-ocation_class option:selected").attr("level");
            $("#c-address_lv_octionlevel").find("option").each(function () {
                if ($(this).attr("value") <= parseInt(level)) {
                    $(this).hide();
                } else {
                    $(this).show();
                }
            });
            $("#c-address_lv_octionlevel").val(parseInt(level) + 1);
        }
        hasweek();
        hasdaytime();
    }
});